<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="经营类型" prop="operatingName">
        <el-select
          v-model="queryParams.operatingName"
          placeholder="商铺状态"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in operatingOptions"
            :key="dict.id"
            :label="dict.operatingName"
            :value="dict.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="管理人名称" prop="managerName">
        <el-input
          v-model="queryParams.managerName"
          placeholder="请输入管理人名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="商铺状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="商铺状态"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="商铺名称" prop="shopName">
        <el-input
          v-model="queryParams.shopName"
          placeholder="请输入商铺名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button
          type="cyan"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
        >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['admin:shop:add']"
        >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['admin:shop:edit']"
        >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['admin:shop:remove']"
        >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['admin:shop:export']"
        >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="shopList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="商铺编号" align="center" prop="id" />
      <el-table-column label="系统编号" align="center" prop="shopHost" />
      <el-table-column label="质押商甲" align="center" prop="shangjia" />
      <el-table-column label="线下质押商甲" align="center" prop="offlineShangjia" />

      <el-table-column
        label="经营类型"
        align="center"
        prop="operatingName"
        :formatter="operatingFormatter"
      />
      <el-table-column label="管理人名称" align="center" prop="managerName" />
      <el-table-column label="管理人电话" align="center" prop="managerPhone" />
      <el-table-column label="商铺名称" align="center" prop="shopName" />
      <el-table-column label="营业执照" align="center" prop="shopImage">
        <template slot-scope="scope">
          <el-image
            style="width: 100px; height: 100px"
            :src="scope.row.shopImage"
            :preview-src-list="[scope.row.shopImage]"
          >
          </el-image>
        </template>
      </el-table-column>

      <el-table-column label="logo" align="center" prop="shopLogo">
        <template slot-scope="scope">
          <el-image
            style="width: 100px; height: 100px"
            :src="scope.row.shopLogo"
            :preview-src-list="[scope.row.shopLogo]"
          >
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="营业时间" align="center" prop="operatingTime" />
      <el-table-column label="商铺电话" align="center" prop="shopMobile" />
      <el-table-column label="商铺公告" align="center" prop="shopNotice" />

      <el-table-column
        label="商铺状态"
        align="center"
        prop="status"
        :formatter="statusFormat"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['admin:shop:edit']"
          >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['admin:shop:remove']"
          >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改商铺对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1200px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
        <el-form-item   v-hasPermi="['system:shop:field']" label="商铺状态" prop="status">
          <el-select
            v-model="form.status"
            placeholder="商铺状态"
            clearable
            size="small"
          >
            <el-option
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="线下消费比例" prop="lineCustomer">
          <el-input-number
            v-model="form.lineCustomer"
            :precision="0"
            :step="1"
            :min="1"
            :max="100"
          ></el-input-number>
        </el-form-item>
        <el-form-item label="质押线下商甲" prop="offlineShangjia">
          <el-input-number
            v-model="form.offlineShangjia"
            :precision="3"
            :step="0.1"
            :max="10000"
          ></el-input-number>
        </el-form-item>

        <el-form-item label="质押商甲" prop="shangjia">
          <el-input-number
            v-model="form.shangjia"
            :precision="3"
            :step="0.1"
            :max="10000"
          ></el-input-number>
        </el-form-item>


        <el-form-item v-if="form.status == 1" label="商铺收款码" prop="shopPay">
          <img v-if="form.shopPay" :src="form.shopPay" class="avatar" />
          <i class="el-icon-download" @click="downLoad(form.shopPay)"></i>
        </el-form-item>

        <el-form-item label="商铺省市县" prop="citys">
          <el-input v-model="form.citys" disabled size="small" />
        </el-form-item>

        <el-form-item label="商铺详细地址" prop="addrInfo">
          <el-input
            v-model="form.addrInfo"
            type="textarea"
            placeholder="请输入商铺详细地址"
          />
        </el-form-item>

        <el-form-item label="商铺公告" prop="shopNotice">
          <el-input
            v-model="form.shopNotice"
            type="textarea"
            placeholder="请输入商铺公告"
          />
        </el-form-item>

        <el-form-item label="经营类型" prop="operatingName">
          <el-select
            v-model="form.operatingName"
            placeholder="经营类型"
            clearable
            size="small"
          >
            <el-option
              v-for="dict in operatingOptions"
              :key="dict.id"
              :label="dict.operatingName"
              :value="dict.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="管理人名称" prop="managerName">
          <el-input v-model="form.managerName" placeholder="请输入管理人名称" />
        </el-form-item>
        <el-form-item label="管理人电话" prop="managerPhone">
          <el-input
            v-model="form.managerPhone"
            placeholder="请输入管理人电话"
          />
        </el-form-item>



        <el-form-item label="系统商户编号" prop="shopHost">
          <el-input
            v-model="form.shopHost"
            disabled
            placeholder="请输入系统商户编号"
          />
        </el-form-item>

        <el-form-item label="商铺封面" prop="shopCover">
          <el-upload
            class="avatar-uploader"
            :action="fileUrl"
            :show-file-list="false"
            :on-success="successFile2"
            :before-upload="beforeAvatarUpload2"
          >
            <img v-if="form.shopCover" :src="form.shopCover" class="avatar" />
            <i v-else class="el-icon-plus avatar-uploader-icon"/>
          </el-upload>
        </el-form-item>


        <el-form-item label="身份证-正面" prop="realJust">
          <el-upload
            class="avatar-uploader"
            :action="fileUrl"
            :show-file-list="false"
            :on-success="successFileRealJust"
            :before-upload="beforeAvatarUpload2"
          >
            <img v-if="form.realJust" :src="form.realJust" class="avatar" />
            <i v-else class="el-icon-plus avatar-uploader-icon"/>
          </el-upload>
        </el-form-item>


        <el-form-item label="身份证-反面" prop="realBack">
          <el-upload
            class="avatar-uploader"
            :action="fileUrl"
            :show-file-list="false"
            :on-success="successFileRealBack"
            :before-upload="beforeAvatarUpload2"
          >
            <img v-if="form.realBack" :src="form.realBack" class="avatar" />
            <i v-else class="el-icon-plus avatar-uploader-icon"/>
          </el-upload>
        </el-form-item>


        <el-form-item label="商铺名称" prop="shopName">
          <el-input v-model="form.shopName" placeholder="请输入商铺名称" />
        </el-form-item>
        <el-form-item label="商铺电话" prop="shopMobile">
          <el-input v-model="form.shopMobile" placeholder="请输入商铺电话" />
        </el-form-item>

        <el-form-item label="评分" prop="shopScore">
          <el-rate disabled v-model="form.shopScore"></el-rate>
        </el-form-item>

        <el-form-item label="评分"  v-hasPermi="['system:shop:field']" prop="shopScore">
          <el-rate  v-model="form.shopScore"></el-rate>
        </el-form-item>

        <el-form-item label="人均消费" prop="shopSvg">
          <el-input v-model="form.shopSvg" placeholder="请输入人均消费" />
        </el-form-item>

        <el-form-item label="营业时间" prop="operatingTime">
          <el-time-picker
            is-range
            v-model="form.operatingTime"
            range-separator="~"
            value-format="HH:mm"
            format="HH:mm"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            placeholder="选择时间范围"
          >
          </el-time-picker>
        </el-form-item>

        <el-form-item label="商铺简介" prop="shopInfo">
          <el-input
            v-model="form.shopInfo"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>

        <el-form-item label="营业执照" prop="shopImage">
          <el-upload
            class="avatar-uploader"
            :action="fileUrl"
            :show-file-list="false"
            :on-success="successFile1"
            :before-upload="beforeAvatarUpload1"
          >
            <img v-if="form.shopImage" :src="form.shopImage" class="avatar" />
            <i v-else class="el-icon-plus avatar-uploader-icon"/>

          </el-upload>
        </el-form-item>



        <el-form-item label="商铺logo" prop="shopLogo">
          <el-upload
            class="avatar-uploader"
            :action="fileUrl"
            :show-file-list="false"
            :on-success="successFile"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="form.shopLogo" :src="form.shopLogo" class="avatar" />
            <i v-else class="el-icon-plus avatar-uploader-icon"/>

          </el-upload>
        </el-form-item>



        <el-form-item label="商铺客服二维码" prop="shopQr">
          <el-upload
            class="avatar-uploader"
            :action="fileUrl"
            :show-file-list="false"
            :on-success="successFileQr"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="form.shopQr" :src="form.shopQr" class="avatar" />
            <i v-else class="el-icon-plus avatar-uploader-icon"/>

          </el-upload>
        </el-form-item>

        <!-- <el-form-item label="范围m为单位" prop="dataRange">
          <el-input v-model="form.dataRange" placeholder="请输入数据设定-范围m为单位" />
        </el-form-item> -->
        <el-row>
          <!-- <el-form-item label="年龄设定" prop="dataAge">
            <el-col :span="3">
              <el-input
                v-model="form.dataAge1"
                placeholder="请输入年龄开始"
                size="small"
              />
            </el-col>
            <el-col :span="3" class="topStyle">
              <span> ~ </span>
            </el-col>
            <el-col :span="3">
              <el-input
                v-model="form.dataAge2"
                placeholder="请输入年龄结束"
                size="small"
              />
            </el-col>
          </el-form-item> -->
        </el-row>
        <el-form-item label="性别设定" prop="dataSex">
          <el-select
            v-model="form.dataSex"
            placeholder="年龄设定"
            clearable
            size="small"
          >
            <el-option
              v-for="dict in sexOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>

        <el-row>
          <el-form-item label="收入设定" prop="dataIncome">
            <el-col :span="3">
              <el-input
                v-model="form.dataIncome1"
                placeholder="请输入收入开始"
                size="small"
              />
            </el-col>
            <el-col :span="3" class="topStyle">
              <span> ~ </span>
            </el-col>
            <el-col :span="3">
              <el-input
                v-model="form.dataIncome2"
                placeholder="请输入收入结束"
                size="small"
              />
            </el-col>
          </el-form-item>
        </el-row>

        <el-form-item label="驳回原因" prop="turndown" v-if="form.status == 2">
          <el-input
            v-model="form.turndown"
            type="textarea"
            placeholder="请输入驳回原因"
          />
        </el-form-item>

        <!-- 地图 -->
        <el-form-item label="我的店铺位置" prop="POI">
          <el-amap-search-box
            class="el-vue-search-box-container"
            :search-option="searchOption"
            :on-search-result="onSearchResult"
          ></el-amap-search-box>
          <el-amap
            vid="shopPoi"
            :zoom="zoom"
            :plugin="plugin"
            :amapManager="amapManager"
            :events="events"
            class="shopPoi"
            :center="center"
          >
            <el-amap-marker
              :position="center"
              animation="AMAP_ANIMATION_NONE"
              :title="form.shopName"
              :click="showShopInfo(this)"
              :draggable="true"
              :clickable="true"
              :icon="getIcon()"
            />
          </el-amap>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listShop,
  getShop,
  delShop,
  addShop,
  updateShop,
  exportShop,
} from "@/api/admin/shop";
import { listOperating } from "@/api/admin/operating";
import { codeConversionName } from "@/api/admin/common";
import { getByBusId } from "@/api/admin/pol";
import { fileUrl } from "@/constant/constant";
import { AMapManager } from "vue-amap";
let amapManager = new AMapManager();
let Geocoder = null;
export default {
  name: "Shop",
  data() {
    let self = this;
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],

      fileUrl: "",
      amapManager,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商铺表格数据
      shopList: [],
      markers: [],
      // 弹出层标题
      title: "",
      sexOptions: [],
      // 是否显示弹出层
      open: false,
      searchOption: {
        city: "",
        citylimit: false,
      },
      center: [120.19, 30.26],
      events: {
        init: (o) => {
          o.getCity((result) => {
            // console.log(result);
          });
        },
        moveend: () => {},
        zoomchange: () => {},
        click: (e) => {
          self.center = [e.lnglat.lng, e.lnglat.lat];
          self.form.longitude = e.lnglat.lng;
          self.form.latitude = e.lnglat.lat;
          Geocoder.getAddress(self.center, function (status, result) {
            //根据坐标获取位置
            if (status === "complete" && result.info === "OK") {
              self.input = result.regeocode.formattedAddress;
              document.querySelector(".search-box-wrapper input").value =
                self.input;
            }
          });
        },
      },
      zoom: 14,
      plugin: [
        {
          pName: "Geocoder", //使用AMap.Geocoder插件
          events: {
            init(o) {
              Geocoder = o; // o 则是AMap.Geocoder的实例 对外部的Geocoder变量进行赋值，在任何地方就都可以使用了
              //self.center 具体坐标 （数组格式） ，function 回调函数
              o.getAddress(self.center, function (status, result) {
                if (status === "complete" && result.info === "OK") {
                  //result.regeocode.formattedAddress就是具体位置
                  self.input = result.regeocode.formattedAddress;
                  //对搜索组件的input进行赋值
                  document.querySelector(".search-box-wrapper input").value =
                    self.input;
                }
              });
            },
          },
        },
        {
          showMarker: true, //定位成功后在定位到的位置显示点标记，默认：true
          pName: "Geolocation", // AMap-Geolocation 定位插件
          events: {
            init(o) {
              //getCurrentPosition 获取当前位置的方法
              //注意 虽然进页面就会调用这个方法，但是data()中center要有默认值，不然会报错
              o.getCurrentPosition((status, result) => {
                if (result && result.position) {
                  let lng = result.position.lng;
                  let lat = result.position.lat;
                  self.center = [lng, lat];
                  self.loaded = true;
                  self.zoom = 14;
                  //result.formattedAddress就是具体位置
                  self.input = result.formattedAddress;
                  //对搜索组件的input进行赋值
                  document.querySelector(".search-box-wrapper input").value =
                    self.input;
                  self.$nextTick();
                }
              });
            },
          },
        },
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,

        shangjia: null,

        operatingName: null,

        managerName: null,

        managerPhone: null,

        shopHost: null,

        shopName: null,

        shopInfo: null,

        shopImage: null,

        dataRange: null,

        dataSex: null,

        dataAge: null,

        dataIncome: null,

        status: null,

        turndown: null,
      },
      // 表单参数
      form: {},
      // 状态数据字典
      statusOptions: [],
      operatingOptions: [],
      // 表单校验
      rules: {
        operatingName: [
          {
            required: true,
            message: "经营类型,存储类型名称不能为空",
            trigger: "blur",
          },
        ],

        managerName: [
          { required: true, message: "管理人名称不能为空", trigger: "blur" },
        ],

        managerPhone: [
          {
            required: true,
            message: "管理人电话，数据不能为空",
            trigger: "blur",
          },
        ],

        shopHost: [
          { required: true, message: "系统商户编号不能为空", trigger: "blur" },
        ],

        shopName: [
          { required: true, message: "商铺名称不能为空", trigger: "blur" },
        ],
        shopMobile: [
          { required: true, message: "商铺电话不能为空", trigger: "blur" },
        ],
        shopNotice: [
          { required: true, message: "商铺公告不能为空", trigger: "blur" },
        ],
        lineCustomer: [
          { required: true, message: "线下消费比例不可为空", trigger: "blur" },
         // { min:1,max:100, message: "最小值1,最大值100", trigger: "blur" },

        ],
      },
    };
  },
  created() {
    this.getList();
    this.getDicts("shop_status").then((response) => {
      this.statusOptions = response.data;
    });
    this.getDicts("sex_status").then((response) => {
      this.sexOptions = response.data;
    });
    listOperating({ pageNum: 1, pageSize: 100000 }).then((res) => {
      this.operatingOptions = res.rows;
    });
    this.fileUrl = fileUrl;
  },
  methods: {
    /** 查询商铺列表 */
    getList() {
      this.loading = true;
      listShop(this.queryParams).then((response) => {
        this.shopList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 能够得到所有源数据。
    showShopInfo(e) {
      // console.log(e)
    },
    successFile1(res, file) {
      this.form.shopImage = URL.createObjectURL(file.raw);
      this.form.shopImage = res.data;
    },
    beforeAvatarUpload1(file) {
      const isLt2M = file.size / 1024 / 1024 < 2;
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isLt2M;
    },

    successFileRealJust(res, file) {
      this.form.realJust = URL.createObjectURL(file.raw);
      this.form.realJust = res.data;
    },
    successFileRealBack(res, file) {
      this.form.realBack = URL.createObjectURL(file.raw);
      this.form.realBack = res.data;
    },
    beforeAvatarUpload2(file) {
      const isLt2M = file.size / 1024 / 1024 < 2;
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isLt2M;
    },
    successFile(res, file) {
      this.form.shopLogo = URL.createObjectURL(file.raw);
      this.form.shopLogo = res.data;
    },
    successFileQr(res, file) {
      this.form.shopQr = URL.createObjectURL(file.raw);
      this.form.shopQr = res.data;
    },
    beforeAvatarUpload(file) {
      const isLt2M = file.size / 1024 / 1024 < 2;
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isLt2M;
    },
    // 字典状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    operatingFormatter(row, column) {
      var tempList = this.operatingOptions.filter(
        (item) => item.id == row.operatingName
      );
      if (tempList.length != 0) {
        return tempList[0].operatingName;
      }
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,

        userId: null,

        shangjia: null,

        operatingName: null,

        managerName: null,

        managerPhone: null,

        shopHost: null,

        shopName: null,

        shopInfo: null,

        shopImage: null,

        dataRange: null,

        dataSex: null,

        dataAge: null,

        dataIncome: null,

        status: 0,

        turndown: null,

        createBy: null,

        createTime: null,

        updateBy: null,

        updateTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    //点击搜索后触发的事件
    onSearchResult(pois) {
      this.input = document.querySelector(".search-box-wrapper input").value;
      //这边类似模糊查询 会返回一个数组，我就直接取第一个值了。
      this.zoom = 100;
      this.center = [pois[0].lng, pois[0].lat];
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商铺";
      this.$set(this.form, "offlineShangjia", 17.000)

    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getShop(id).then((response) => {
        this.form = response.data;
        this.form.status = this.form.status + "";
        this.form.dataSex = this.form.dataSex + "";
        if (this.form.lineCustomer == null){
          this.$set(this.form, "lineCustomer", 17.00)

        }
        // 查询 对应的 poi 信息
        getByBusId(id).then(async (res) => {
          res = res.data;
          this.form.province = res.province;
          this.form.city = res.city;
          this.form.area = res.area;
          this.form.addrInfo = res.addrInfo;
          this.form.latitude = res.latitude;
          this.form.longitude = res.longitude;
          this.form.shopScore = Number.parseInt(this.form.shopScore);
          this.form.citys = "";
          if (this.form.dataAge != null) {
            this.form.dataAge1 = this.form.dataAge.split("~")[0];
            this.form.dataAge2 = this.form.dataAge.split("~")[1];
          }
          if (this.form.dataIncome != null) {
            this.form.dataIncome1 = this.form.dataIncome.split("~")[0];
            this.form.dataIncome2 = this.form.dataIncome.split("~")[1];
          }

          if (this.form.operatingTime != null) {
            this.form.operatingTime = this.form.operatingTime.split("~");
          }

          var tempCitys = await this.commCode(this.form.province);
          this.form.citys += tempCitys.data + "/";
          tempCitys = await this.commCode(this.form.city);
          this.form.citys += tempCitys.data + "/";
          tempCitys = await this.commCode(this.form.area);
          this.form.citys += tempCitys.data;
          this.open = true;
          // 得到申请最后一个街道地址
          this.searchOption.city = await this.commCode(this.form.area);
          // 如果是有坐标的那么就使用坐标
          if (this.form.latitude != null && this.form.longitude != null) {
            this.center = [this.form.longitude, this.form.latitude];
          }
          this.title = "修改商铺";
        });
      });
    },

    async commCode(code) {
      return await codeConversionName(code);
    },
    getIcon() {
      var tempIcon = this.operatingOptions.filter(
        (item) => item.id == this.form.operatingName
      );
      return new AMap.Icon({
        size: new AMap.Size(35, 45), // 图标尺寸
        // 商户尺寸地图标注点地图
        image: tempIcon.length >= 1 ? tempIcon[0].iconUrl : "", // Icon的图像
        imageOffset: new AMap.Pixel(0, 0), // 图像相对展示区域的偏移量，适于雪碧图等
        imageSize: new AMap.Size(30, 40), // 根据所设置的大小拉伸或压缩图片
        fitZoom: 14, //最合适的级别，在此级别下显示为原始大小
        scaleFactor: 2, //地图放大一级的缩放比例系数
        maxScale: 2, //最大放大比例
        minScale: 1, //最小放大比例
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (this.form.lineCustomer <=0){
          this.msgSuccess("线下让利比只能大于等于一")
          return
        }
        if (valid) {
          if (this.form.operatingTime.length >= 1) {
            var tempTime = this.form.operatingTime;
            this.form.operatingTime = tempTime[0] + "~" + tempTime[1];
          }
          if (this.form.dataAge1 != null && this.form.dataAge2 != null) {
            this.form.dataAge = this.form.dataAge1 + "~" + this.form.dataAge2;
          }

          if (this.form.dataIncome1 != null && this.form.dataIncome2 != null) {
            this.form.dataIncome =
              this.form.dataIncome1 + "~" + this.form.dataIncome2;
          }

          if (this.form.id != null) {
            updateShop(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addShop(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },

    downLoad(imageUrl){
      location.href = imageUrl;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除商铺编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delShop(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有商铺数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportShop(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        });
    },
  },
};
</script>

<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
.topStyle {
  padding-left: 30px;
}
</style>

<style lang="scss" scoped>
.shopPoi {
  height: 700px;
  width: 1000px;
}
.el-vue-search-box-container {
  width: 100% !important;
  margin-bottom: 10px;
}
</style>
